﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Rhomble.Data.Customers;

namespace Rhomble.Services.Customers
{
	public class CustomerService
	{
		private CustomerRepository _repo;
		private string _userName;

		public CustomerService(string userName)
		{
			_repo = new CustomerRepository(userName);
			_userName = userName;
		}

		public IList<CustomerModel> GetAll()
		{
			var customers = _repo.GetQuery()
							.DefaultOrder()
							.Select(CustomerTransforms.EntityToModel)
							.ToList();

			return customers;
		}

		public CustomerModel GetByID(Guid customerID)
		{
			var customer = _repo.GetQuery()
							.WithID(customerID)
							.Select(CustomerTransforms.EntityToModel)
							.Single();

			return customer;
		}

		public void AddNew(CustomerModel model)
		{
			var entity = CustomerTransforms.ModelToEntity(model);
			_repo.AddNew(entity);
		}

		public void Update(Guid customerID, CustomerModel model)
		{
			var entity = CustomerTransforms.ModelToEntity(model);
			_repo.Update(customerID, entity);
		}
	}
}
